package com.xms.queryview.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xms.datacore.service.FinderService;
import com.xms.queryview.entity.QueryView;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 * QueryviewFinderService
 * </p>
 *
 * @author migo
 * @since 2021/9/3
 */
@CacheConfig(cacheNames = "queryview", keyGenerator = "CacheKeyGenerator")
@Service
public class QueryViewFinderService extends FinderService<QueryView> implements IQueryViewFinderService {
    @Override
    @Cacheable(condition="#id != null")
    public QueryView getById(UUID id) {
        return super.getById(id);
    }

    @Override
    @Cacheable()
    public List<QueryView> getByIds(Collection<UUID> idList) {
        return super.listByIds(idList);
    }

    @Override
    //@Cacheable()
    public QueryView getOne(Wrapper<QueryView> queryWrapper) {
        return super.getOne(queryWrapper);
    }

    @Override
    @Cacheable()
    public int count() {
        return super.count();
    }

    @Override
    //@Cacheable()
    public int count(Wrapper<QueryView> queryWrapper) {
        return super.count(queryWrapper);
    }

    @Override
    //@Cacheable()
    public List<QueryView> list(Wrapper<QueryView> queryWrapper) {
        return super.list(queryWrapper);
    }

    @Override
    @Cacheable()
    public List<QueryView> all() {
        return super.list();
    }

    @Cacheable()
    @Override
    public QueryView getDefaultView(UUID entityId) {
        return super.getOne(new LambdaQueryWrapper<QueryView>().eq(QueryView::getEntityid, entityId)
                .eq(QueryView::getIsdefault, true));
    }

    @Cacheable()
    @Override
    public QueryView getDefaultView(String entityName) {
        return super.getOne(new LambdaQueryWrapper<QueryView>().eq(QueryView::getEntityname, entityName)
                .eq(QueryView::getIsdefault, true));
    }

    @Cacheable()
    @Override
    public List<QueryView> getByEntityId(UUID entityId) {
        return super.list(new LambdaQueryWrapper<QueryView>().eq(QueryView::getEntityid, entityId));
    }

    @Cacheable()
    @Override
    public List<QueryView> getByEntityName(String entityName) {
        return super.list(new LambdaQueryWrapper<QueryView>().eq(QueryView::getEntityname, entityName));
    }

    @Cacheable()
    @Override
    public List<QueryView> getAuthorizedByEntityId(UUID entityId) {
        return super.list(new LambdaQueryWrapper<QueryView>().eq(QueryView::getEntityid, entityId).eq(QueryView::getStatecode, true));
    }

    @Cacheable()
    @Override
    public List<QueryView> getAuthorizedByEntityName(String entityName) {
        return super.list(new LambdaQueryWrapper<QueryView>().eq(QueryView::getEntityname, entityName).eq(QueryView::getStatecode, true));
    }

    @Cacheable()
    @Override
    public List<QueryView> getAuthorized(LambdaQueryWrapper<QueryView> queryWrapper) {
        queryWrapper.eq(QueryView::getStatecode, true);
        return super.list(queryWrapper);
    }

    @Cacheable()
    @Override
    public List<QueryView> getAuthorizations() {
        return super.list(new LambdaQueryWrapper<QueryView>().eq(QueryView::getAuthorizationenabled, true));
    }
}
